﻿using System;
using System.Collections.Generic;
using System.Web;
using ORS.DAL;

namespace ORS.BLL
{
    public class Authentication
    {
        string sqlstr1;
        string sqlstr2;
        string sqlstr3;
        static mssqlopr ivk_mssqlopr;
        int number;

       static Authentication()
        {
            ivk_mssqlopr = new mssqlopr();
        }
        
       
        
        
        
        
        
        public int IsUserExisting(string tb_name, string user_name, string user_password)
        {
            sqlstr1 = "SELECT * FROM " + tb_name + " WHERE userid='" + user_name + "'";
            sqlstr2 = "SELECT * FROM " + tb_name + " WHERE userid='" + user_name + "' AND password='" + user_password + "'";
            sqlstr3 = "SELECT * FROM " + tb_name + " WHERE userid='" + user_name + "' AND validflag = 1";
            if (tb_name == "tb_admin")
            {
                if (!ivk_mssqlopr.find_User(sqlstr1))
                {
                    number = 1;
                    return number;
                }
                else if (!ivk_mssqlopr.find_User(sqlstr2))
                {
                    number = 2;
                    return number;
                }
                else
                {
                    number = 4;
                    return number;
                }
            }
            else
            {
                if (!ivk_mssqlopr.find_User(sqlstr1))
                {
                    number = 1;
                    return number;
                }
                else if (!ivk_mssqlopr.find_User(sqlstr2))
                {
                    number = 2;
                    return number;
                }
                else if (!ivk_mssqlopr.find_User(sqlstr3))
                {
                    number = 3;
                    return number;
                }
                else
                {
                    number = 4;
                    return number;
                }
            }
        }
    }
}